package com.Service.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Dao.BaseDaoI;
import com.Entity.Favoritetopic;
import com.Service.FavoriteTopicService;
@Service("favoriteTopicService")
public class FavoriteTopicServiceImpl extends BaseServiceImpl<Favoritetopic> implements FavoriteTopicService {

	@Autowired
	private BaseDaoI<Favoritetopic> favoritetopicdao;
	List<Favoritetopic> favoritetopiclist=new ArrayList<Favoritetopic>();
	
	@Override
	public boolean getFavorited(int userid, long topicid) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userid);
		params.put("topicId", topicid);
		String hql = "from Favoritetopic t where t.userId = :userId and t.topicId = :topicId";	
		favoritetopiclist=this.favoritetopicdao.find(hql, params);
		if(favoritetopiclist.size()>0){
			System.out.println("favoritetopiclist.size():"+favoritetopiclist.size());
			return true;
		}
		return false;
	}

	@Override
	public List<Favoritetopic> getFavoriteTopicList(int userid,int page,int rows) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userid);
		String hql = "from Favoritetopic t where t.userId = :userId";	
		favoritetopiclist=this.favoritetopicdao.find(hql, params, page, rows);
		return favoritetopiclist;
	}

	@Override
	public Long countFavoriteTopicByUserId(Integer userId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		String hql="select count(*) from Favoritetopic t where t.userId=:userId";
		return favoritetopicdao.count(hql, params);
	}

}
